package com.test.thread;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.*;

public class ThreadPoolDemo {

    private static  final ScheduledExecutorService executor=new
            ScheduledThreadPoolExecutor(1, Executors.defaultThreadFactory());

    private  static SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static void main(String[] args) {
        executor.scheduleWithFixedDelay(new Runnable() {
            @Override
            public void run() {
                if(haveMsgAtCurrent()){
                    System.out.println(sdf.format(new Date())+ "\n发布消息！");
                }
            }
        },1,1, TimeUnit.SECONDS);
    }
        public static boolean haveMsgAtCurrent(){
            return true;
        }
}
